package alp.starcode.user.controller;

import alp.starcode.framework.utils.JSONResult;
import alp.starcode.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@Api(tags = "用户相关接口")
@RestController
@RequestMapping("users")
public class UserController {

    @Autowired
    UserService userService;

    @ApiOperation("用户注册（除商家外）")
    @PostMapping("userRegister.do")
    public JSONResult userRegister(String userAccount,String userPassword,String userName,String type){
        return JSONResult.ok(userService.registerBuyers(userAccount, userPassword, userName, type));
    }

    @ApiOperation("用户注册（商家）")
    @PostMapping("sellerRegister.do")
    public JSONResult sellerRegister(String userAccount,String userPassword,String userName,String storeName,String storeAddress,String storePhone){
        return JSONResult.ok(userService.registerSeller(userAccount, userPassword, userName, storeName, storeAddress, storePhone));
    }

    @ApiOperation("用户登录")
    @PostMapping("userLogin.do")
    public JSONResult userLogin(String userAccount, String userPassword, HttpSession httpSession){
        return JSONResult.ok(userService.login(userAccount, userPassword, httpSession));
    }
    @ApiOperation("用户评论")
    @PostMapping("insertComment.do")
    public JSONResult insertComment(String userUuid,String orderUuid,String msg){
        return JSONResult.ok(userService.insertComment(userUuid, orderUuid, msg));
    }
}
